﻿Namespace Midline
    Public Class V_MidLine
        Public startm As Double
        Public bpdlist As List(Of bpd)

        Public Sub New()
            bpdlist = New List(Of bpd)()
        End Sub

        ''' <summary>
        ''' 初始化本体
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function initMySelf()
            For i = 0 To bpdlist.Count - 1
                bpdlist(i).initMySelf()
            Next
            Return Nothing
        End Function
        ''' <summary>
        ''' 根据给定里程获取高程
        ''' </summary>
        ''' <param name="mil"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetEleByMileage(ByRef mil As Double) As Double
            If mil < startm Then
                Return Nothing
            End If
            If bpdlist.Count = 1 Then
                Return bpdlist(0).GetEleByMileage(mil)
            End If
            If bpdlist.Count = 2 Then
                If mil < bpdlist(0).endm Then
                    Return bpdlist(0).GetEleByMileage(mil)
                Else
                    Return bpdlist(1).GetEleByMileage(mil)
                End If
            End If
            If bpdlist.Count > 2 Then
                If mil > startm And mil < bpdlist(1).startm Then
                    Return bpdlist(0).GetEleByMileage(mil)
                Else
                    For i = 1 To bpdlist.Count - 2
                        If (mil > bpdlist(i - 1).endm And mil < bpdlist(i + 1).startm) Then
                            Return bpdlist(i).GetEleByMileage(mil)
                        End If
                    Next
                    If mil > bpdlist(bpdlist.Count - 1).startm Then
                        Return bpdlist(bpdlist.Count - 1).GetEleByMileage(mil)
                    End If
                End If
            End If
            Return Nothing
        End Function
    End Class
End Namespace